

package org.example.design.designmode.proxy.jdkproxy.blinddate;


import org.springframework.cglib.proxy.InvocationHandler;
import org.springframework.cglib.proxy.Proxy;
import java.lang.reflect.Method;

public class JDKProxy implements InvocationHandler {

    private PeopleService trget;

    public PeopleService getInstance(PeopleService pr) {
        System.out.println("启动代理！");
        this.trget = pr;
        Class cl = trget.getClass();
       return (PeopleService) Proxy.newProxyInstance(cl.getClassLoader(), cl.getInterfaces(), this);


    }

    private void before() {
        System.out.println("开始物色！");
    }

    private void after() {
        System.out.println("双方确认交往！");
    }


    @Override
    public Object invoke(Object o, Method me, Object[] objects) throws Throwable {
        System.out.println("调用代理底层！");
        before();
        Object ob = me.invoke(this.trget, objects);
        System.out.println("me.invoke(this.trget, objects)"+ob);
        after();
        return ob;
    }
}
